package com.lai.note.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.lai.note.R;
import com.lai.note.util.ListNoteUtil;
import com.lai.note.util.ToastUtil;

public class ModifyNoteActivity extends AppCompatActivity {

    private String noteId;
    private EditText et_title;
    private EditText et_note;
    private Button btn_note;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_note);
        et_title = findViewById(R.id.et_title);
        et_note = findViewById(R.id.et_note);
        btn_note = findViewById(R.id.btn_note);
        System.out.println("过来了");
//        System.out.println("bundle:-->"+bundle);
//        noteId = bundle.getString("noteId","");
//        String title = bundle.getString("title","");
//        String content = bundle.getString("content","");
        Intent intent = getIntent();
        noteId = intent.getStringExtra("noteId");
        String title = intent.getStringExtra("title");
        String content = intent.getStringExtra("content");
        et_title.setText(title);
        et_note.setText(content);
        onBtnClick();
    }


    private void onBtnClick(){
        btn_note.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                save();
            }
        });
    }

    private void save(){
        String title = et_title.getText().toString();
        String content = et_note.getText().toString();
        if(title == null)
            ToastUtil.display(getApplicationContext(),"请输入标题");
        else if(content == null)
            ToastUtil.display(getApplicationContext(),"请输入笔记内容");
        else{
            ListNoteUtil.userSaveNote(getApplicationContext(),noteId,title,content);
        }

    }


}
